<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script>
			var arr = [1,2,3,3,2,1,5,2,4];
			function del(arr){
				for(var i=0;i<arr.length;i++){
					for(var j=i+1;j<arr.length;j++){
						if(arr[i]==arr[j]){
							arr.splice(j,1);
							j--;
						}
					}
				}
				return arr;
			}
//			console.log(del(arr));
			
			var arr = [1,2,3,3,2,1,5,2,4];
			function del2(arr){
				var newArr = [];
				var obj = {};
				for(var i=0;i<arr.length;i++){
					if(!obj[arr[i]]){
						newArr.push(arr[i]);
						obj[arr[i]] = true;
					}
				}
//				i=0     obj[arr[0]]   obj[1]     newArr  1
//				i=1     obj[arr[1]]   obj[2]     newArr  1,2
//				i=2     obj[arr[2]]   obj[3]     newArr  1,2,3
//				i=3     obj[arr[3]]   obj[3]     newArr  1,2,3
//				i=4     obj[arr[4]]   obj[2]     
				return newArr;
			}
			document.write(del2(arr));
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		</script>
	</body>
</html>
